//
//  ViewController.m
//  CircleAnimation
//
//  Created by J on 16/2/24.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)CAShapeLayer * shapeLayer;
@property(nonatomic,strong)NSTimer * timer;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.shapeLayer = [CAShapeLayer layer];
    self.shapeLayer.frame = CGRectMake(0, 0, 200, 200);
    self.shapeLayer.position = self.view.center;
    self.shapeLayer.borderWidth = 1.0;
    _shapeLayer.fillColor = [UIColor clearColor].CGColor;
    _shapeLayer.strokeColor = [UIColor purpleColor].CGColor;
    
    _shapeLayer.strokeStart =0;
    _shapeLayer.strokeEnd =0;

    
    UIBezierPath* path = [UIBezierPath bezierPathWithOvalInRect: self.shapeLayer.bounds];
    self.shapeLayer.path = path.CGPath;
    [self.view.layer addSublayer:self.shapeLayer];
 
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(circleAnimationTypeTwo) userInfo:nil repeats:YES];
}

- (void)circleAnimationTypeOne{
    
//    _shapeLayer.strokeEnd +=0.01 ;

    _shapeLayer.strokeEnd = arc4random()%100/100.0;

    
}

- (void)circleAnimationTypeTwo{
    CGFloat valueOne = arc4random()%100/100.0;
    CGFloat valueTwo = arc4random()%100/100.0;

    self.shapeLayer.strokeStart = valueOne<valueTwo?valueOne : valueTwo;
    self.shapeLayer.strokeEnd   = valueOne<valueTwo?valueTwo : valueOne;

}
@end
